<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'mingCheng', validatorRules.mingCheng]" placeholder="请输入名称"></a-input>
        </a-form-item>
        <a-form-item label="等级" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['dengJi', validatorRules.dengJi]" :trigger-change="true" dictCode="gkak_dj" placeholder="请选择等级"/>
        </a-form-item>
        <a-form-item label="联系人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'lianXiRen', validatorRules.lianXiRen]" placeholder="请输入联系人"></a-input>
        </a-form-item>
        <a-form-item label="联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'lianXiDianHua', validatorRules.lianXiDianHua]" placeholder="请输入联系电话"></a-input>
        </a-form-item>
        <a-form-item label="地区" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'diQv', validatorRules.diQv]" placeholder="请输入地区"></a-input>
        </a-form-item>
        <a-form-item label="图片" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-upload v-decorator="['tuPian', validatorRules.tuPian]" :trigger-change="true"></j-upload>
        </a-form-item>
        <a-form-item label="简介" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'jianJie', validatorRules.jianJie]" placeholder="请输入简介"></a-input>
        </a-form-item>
        <a-form-item label="地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'diZhi', validatorRules.diZhi]" placeholder="请输入地址"></a-input>
        </a-form-item>
        <a-form-item label="挂号规则" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'guaHaoGuiZe', validatorRules.guaHaoGuiZe]" placeholder="请输入挂号规则"></a-input>
        </a-form-item>
        <a-form-item label="成立时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择成立时间" v-decorator="[ 'chengLiShiJian', validatorRules.chengLiShiJian]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['beiZhu', validatorRules.beiZhu]" rows="4" placeholder="请输入备注"/>
        </a-form-item>
        <a-form-item label="经度" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'jingDu', validatorRules.jingDu]" placeholder="请输入经度"></a-input>
        </a-form-item>
        <a-form-item label="维度" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'weiDu', validatorRules.weiDu]" placeholder="请输入维度"></a-input>
        </a-form-item>
        <a-form-item label="网格码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'wangGeMaId', validatorRules.wangGeMaId]" placeholder="请输入网格码"></a-input>
        </a-form-item>
        <a-form-item label="机构类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['type', validatorRules.type]" :trigger-change="true" dictCode="gkak_sbjglx" placeholder="请选择机构类型"/>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  
  import JUpload from '@/components/jeecg/JUpload'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  
  export default {
    name: "GkakJiGouManageModal",
    components: { 
      JDate,
      JUpload,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          mingCheng: {rules: [
            {required: true, message: '请输入名称!'},
          ]},
          dengJi: {rules: [
            {required: true, message: '请输入等级!'},
          ]},
          lianXiRen: {rules: [
            {required: true, message: '请输入联系人!'},
          ]},
          lianXiDianHua: {rules: [
            {required: true, message: '请输入联系电话!'},
            {pattern:/^1[3456789]\d{9}$/, message: '请输入正确的手机号码!'},
          ]},
          diQv: {rules: [
            {required: true, message: '请输入地区!'},
          ]},
          tuPian: {rules: [
          ]},
          jianJie: {rules: [
          ]},
          diZhi: {rules: [
            {required: true, message: '请输入地址!'},
          ]},
          guaHaoGuiZe: {rules: [
          ]},
          chengLiShiJian: {rules: [
            {required: true, message: '请输入成立时间!'},
          ]},
          beiZhu: {rules: [
          ]},
          jingDu: {rules: [
          ]},
          weiDu: {rules: [
          ]},
          wangGeMaId: {rules: [
          ]},
          type: {rules: [
          ]},
        },
        url: {
          add: "/gkakJiGouManage/add",
          edit: "/gkakJiGouManage/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'mingCheng','dengJi','lianXiRen','lianXiDianHua','diQv','tuPian','jianJie','diZhi','guaHaoGuiZe','chengLiShiJian','beiZhu','jingDu','weiDu','wangGeMaId','type'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'mingCheng','dengJi','lianXiRen','lianXiDianHua','diQv','tuPian','jianJie','diZhi','guaHaoGuiZe','chengLiShiJian','beiZhu','jingDu','weiDu','wangGeMaId','type'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>